﻿using QiBu.Api.Logic;
using QiBu.Api.Map;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace QiBu.Api.Areas.SYS.Controllers
{
    public class UserController : BaseController
    {
        //
        // GET: /SYS/User/

        /// <summary>
        /// 用户
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="pagenum"></param>
        /// <param name="pagesize"></param>
        /// <param name="t"></param>
        /// <param name="key"></param>
        /// <param name="sortdatafield"></param>
        /// <param name="sortorder"></param>
        /// <returns></returns>
        public JsonResult AjaxGet(int pagenum = 1, int pagesize = 50,
            int t = 0, string key = "", string sortdatafield = "", string sortorder = "")
        {
            var list = SYS_UserLogic.Instance.Datas.Where(x => x.Status != -1).ToList();
            return Json(new { totalrecords = list.Count, Rows = list }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <returns></returns>
        public JsonResult AjaxEdit(SYS_User model) 
        {
            return Json(SYS_UserLogic.Instance.Edit(model));
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult AjaxDel(int id)
        {
            var model = SYS_UserLogic.Instance.Find(x => x.UserId == id);
            model.Status = -1;
            return Json(SYS_UserLogic.Instance.Update(model) > 0);
        }

    }
}
